package com.lmy.springCloud.utils;

import lombok.Data;

@Data
public class Result<T> {

    private int code;

    private String msg;

    private T data;

    public Result() {

    }

    public Result(T data) {
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>(data);
        result.code = ResultEnum.OK.getCode();
        result.msg = ResultEnum.OK.getMessage();
        return result;
    }

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = ResultEnum.OK.getCode();
        result.msg = ResultEnum.OK.getMessage();
        return result;
    }

    public static <T> Result<T> success(T data, String msg) {
        Result<T> result = new Result<T>(data);
        result.code = ResultEnum.OK.getCode();
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> error(T data) {
        Result<T> result = new Result<T>(data);
        result.code = ResultEnum.ERROR.getCode();
        result.msg = ResultEnum.ERROR.getMessage();
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = new Result<T>();
        result.code = ResultEnum.ERROR.getCode();
        result.msg = ResultEnum.ERROR.getMessage();
        return result;
    }

    public static <T> Result<T> error(T data, String msg) {
        Result<T> result = new Result<T>(data);
        result.code = ResultEnum.ERROR.getCode();
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> info(ResultEnum resultEnum) {
        Result<T> result = new Result<T>();
        result.code = resultEnum.getCode();
        result.msg = resultEnum.getMessage();
        return result;
    }

    public static <T> Result<T> info(ResultEnum resultEnum, T data) {
        Result<T> result = new Result<T>(data);
        result.code = resultEnum.getCode();
        result.msg = resultEnum.getMessage();
        return result;
    }
}
